package com.mtiiot.fsmanage.controller;



import com.mtiiot.fsmanage.server.EsServer;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@SuppressWarnings("all")
@Controller
public class EsController {

	@Autowired
    private EsServer esServer;


    /**
     * 系统树获取根节点节点
     * @return
     */
    @RequestMapping(value="/es/getRootNode.action",produces="application/json;charset=UTF-8")
    @ResponseBody
    public Object getRootNode() throws Exception {
        Object obj=esServer.getRootNode();
        ObjectMapper mapper = new ObjectMapper();
        String jsonStr=mapper.writeValueAsString(obj);
        return jsonStr;
    }

    /**
     * 系统树获取根节点节点
     * @return
     */
    @RequestMapping(value="/es/getChildrenNode.action",produces="application/json;charset=UTF-8")
    @ResponseBody
    public Object getChildrenNode(String id,String index) throws Exception{
        Object obj = esServer.getChildrenNode(id,index);
        ObjectMapper mapper = new ObjectMapper();
        String jsonStr=mapper.writeValueAsString(obj);
        return jsonStr;
    }

    /**
     * 系统树获取根节点节点
     * @return
     */
    @RequestMapping(value="/es/esQuery.action",produces="application/json;charset=UTF-8")
    @ResponseBody
    public Object esQuery(String index,String type,String times,String queryKeyWord,int count,String sort) throws Exception{
        Object obj = esServer.esQuery(index,type,times,queryKeyWord,count,sort);
        ObjectMapper mapper = new ObjectMapper();
        String jsonStr=mapper.writeValueAsString(obj);
        return jsonStr;
    }

}